home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Pascal / Snippets / Keys / Keys.p
Encoding:
Text File  |  1996-06-01  |  1.3 KB  |  42 lines  |  [TEXT/PJMM]

  1. { This code demonstrates how to use the Event Manager in order to }
  2. { get a single character from the keyboard like when you use }
  3. { the ReadKey function of Borland/Turbo Pascal. }
  4. { I myself use this program to determine the ASCII codes }
  5. { for special keys like the arrow keys. }
  6. { This code is Public Domain. You can do what you want with it, }
  7. { even sell it (although I don't think anyone will buy it :-) }
  8. { It should run both with CodeWarrior and THINK Pascal. No project is }
  9. { included because the project would be larger than the source code... }
  10. { If you have further questions, feel free to contact me }
  11. { Matthias Wuttke <wuttke@stein.teuto.de>}
  12.  
  13. PROGRAM Keys;
  14.  
  15. {$IFC UNDEFINED THINK_Pascal}
  16.     USES
  17.         Types, QuickDraw, Fonts, Windows, Events, Menus, TextEdit, Dialogs, Memory;
  18. {$ENDC}
  19.  
  20.     VAR
  21.         ch: CHAR;
  22.         evt: EventRecord;
  23.         dummy: BOOLEAN;
  24.  
  25. BEGIN
  26. {$IFC DEFINED THINK_PASCAL}
  27.     ShowText;
  28. {$ENDC}
  29.     REPEAT
  30.         WriteLn('Press key, ''q'' for quit');
  31.  
  32.         REPEAT
  33.             dummy := WaitNextEvent(keyDownMask, evt, 30, NIL);
  34.         UNTIL evt.what = keyDown;
  35.  
  36.         ch := CHAR(BAnd(evt.message, charCodeMask));
  37.         WriteLn('Character        = ''', ch, '''');
  38.         WriteLn('ASCII Code       = ', BAnd(evt.message, charCodeMask) : 1);
  39.         WriteLn('Virtual Key Code = ', BAnd(evt.message, keyCodeMask) : 1);
  40.         WriteLn;
  41.     UNTIL ch = 'q';
  42. END.